package ObjectVC;

import java.util.ArrayList;
import javax.swing.JOptionPane;

public aspect LockedObjects {
	void around (Object obj) : set(* *.*)&&args(obj) && withincode(* *.*(..)) 
	&& !within(ObjectVC.*) && !within(DB.*){
		if (null != obj && DB.isLocked(obj))
			JOptionPane.showMessageDialog(null, obj.toString() + "is locked, value remains the same");
		proceed(obj);
	}
	
	after(Object actualObj, Action action, ArrayList<Object> actionParams): 
		VCOperations.VCops(actualObj, action, actionParams) 
		&& if(action.equals(Action.Lock) || action.equals(Action.Unlock)){
		if (null != actionParams && actionParams.size()>0){
			Object obj = actionParams.get(0);
			
			if (null != obj){
				if(action.equals(Action.Lock))
					DB.lockObject(obj);
				
				else if(action.equals(Action.Unlock))
					DB.unlockObject(obj);				
			}

			JOptionPane.showMessageDialog(null, "Object is null");
		}
	}
}
